namespace ScrumSprintMonitor.UI.Wpf.Avatars
{
	#region #using Directives

	using System;
	using System.ComponentModel.Composition;
	using System.Windows;
	using System.Windows.Media;

	using Infrastructure;

	#endregion

	[Export(typeof(IAvatarProvider))]
	internal class SolidColorAvatarProvider : IAvatarProvider
	{
		#region IAvatarProvider Members

		public string ProviderId
		{
			get { return "color"; }
		}

		public IAvatar GetAvatar(string avatarKey)
		{
			var brushConverter = new BrushConverter();

			return new WpfSolidBrushAvatar((Brush) brushConverter.ConvertFrom(avatarKey));
		}

		#endregion
	}

	internal class WpfSolidBrushAvatar : IAvatar
	{
		private readonly Brush brush;

		public WpfSolidBrushAvatar(Brush brush)
		{
			this.brush = brush;
		}

		#region Implementation of IAvatar

		public object GetRepresentation(Type representationType)
		{
			if (representationType == null)
			{
				throw new ArgumentNullException("representationType");
			}

			if (representationType == typeof(ImageSource))
			{
				var aGeometryDrawing = new GeometryDrawing {
				                                           	Geometry = new RectangleGeometry(new Rect(new Size(80, 80))),
				                                           	Brush = this.brush
				                                           };

				return new DrawingImage(aGeometryDrawing);
			}

			throw new ArgumentException("Invalid representation type.", "representationType");
		}

		#endregion
	}
}